const express = require('express');
const router = express.Router();
const BackupController = require('../controllers/BackupController');
const authenticate = require('../middleware/auth');

/**
 * @swagger
 * tags:
 *   name: Backup
 *   description: 数据备份和恢复
 */

// All routes require authentication
router.use(authenticate);

/**
 * @swagger
 * /api/backup/create:
 *   post:
 *     summary: 创建数据库备份
 *     tags: [Backup]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 备份创建成功
 *       500:
 *         description: 服务器内部错误
 */
router.post('/create', BackupController.createBackup);

/**
 * @swagger
 * /api/backup/list:
 *   get:
 *     summary: 列出所有可用的备份
 *     tags: [Backup]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 成功获取备份列表
 *       500:
 *         description: 服务器内部错误
 */
router.get('/list', BackupController.listBackups);

/**
 * @swagger
 * /api/backup/restore:
 *   post:
 *     summary: 恢复数据库备份
 *     tags: [Backup]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - backup_file
 *             properties:
 *               backup_file:
 *                 type: string
 *                 description: 备份文件名
 *     responses:
 *       200:
 *         description: 备份恢复指令
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 备份文件未找到
 *       500:
 *         description: 服务器内部错误
 */
router.post('/restore', BackupController.restoreBackup);

/**
 * @swagger
 * /api/backup/download/{backup_file}:
 *   get:
 *     summary: 下载备份文件
 *     tags: [Backup]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: backup_file
 *         required: true
 *         schema:
 *           type: string
 *         description: 备份文件名
 *     responses:
 *       200:
 *         description: 备份文件下载
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 备份文件未找到
 *       500:
 *         description: 服务器内部错误
 */
router.get('/download/:backup_file', BackupController.downloadBackup);

module.exports = router;